home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 5477 < prev    next >
Encoding:
Text File  |  1996-08-05  |  1.4 KB  |  56 lines

  1. Newsgroups: comp.lang.c
  2. Path: EU.net!sun4nl!hcsrnd!root
  3. From: paulw@gti-ia.nl (Paul Wallis)
  4. Subject: Pre-processing:  Can this be done?
  5. Message-ID: <DMGo4t.7r7@gti-ia.nl>
  6. Sender: root@gti-ia.nl (Operator)
  7. Reply-To: paulw@gti-ia.nl
  8. Organization: GTI Industrial Automation, Apeldoorn
  9. Date: Thu, 8 Feb 1996 14:26:52 GMT
  10.  
  11. Hi all,
  12.  
  13. I'm trying to write a function which will print trace statements.
  14. I want the file and line to be added to the argument list
  15. automatically.  I am, however, having some problems working
  16. my way around the pre-processor. I would like to be able to enter
  17. the following line:
  18.  
  19.     trace("%d, %f", an_int, a_float);
  20.  
  21. and have the arguments passed as so:
  22.  
  23.     _trace(__FILE__, __LINE__, "%d, %f", an_int, a_float);
  24.  
  25. I have defined a macro trace so:
  26.  
  27.     #define trace(x) _trace(__FILE__, __LINE__, x)
  28.  
  29. Now what I've found is that the pre-processor 'throws a wobbler'
  30. at the x.  Apparently not liking multiple arguments.  Is there
  31. any way to get it to accept this, without having to do this,
  32. which is very ugly:
  33.  
  34.     trace(("%d, %f", an_int, a_float));
  35.  
  36. I have also tried redefining a macro as such:
  37.  
  38.     #define trace( _trace(__FILE__, __LINE__
  39.  
  40. but to no avail.  Is there an answer, or am I stuck with the
  41. ugly?
  42.  
  43. Thanks in advance for any help,
  44.  
  45.     Paul
  46.  
  47. ---
  48.     =     =
  49.       ===   ===      GTI            Contact me at
  50.    ============      Industrial        paulw@gti-ia.nl
  51.         =     =      Automation b.v.       
  52.       ===   ===                My opinions are
  53.    ============   The Netherlands    Mine all mine!
  54.  
  55.  
  56.